﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace AppBrowser
{
    public partial class frmOptions : Form
    {
        public Dictionary<string, object> OptionList = new Dictionary<string, object>();
        
        public frmOptions()
        {
            InitializeComponent();
        }

        private void frmOptions_Load(object sender, EventArgs e)
        {
            OptionList.Add("general", new OptionGeneral(panelForm));
            // OptionList.Add("download", new OptionDownloads(panelForm));
        }

        private void treeView1_AfterSelect(object sender, TreeViewEventArgs e)
        {
            // clear all controls on the panel
            panelForm.Controls.Clear();
            DetermineOption();


        }


        private void DetermineOption()
        {
            string OptionName = treeView1.SelectedNode.Text.ToString().ToLower();
            if (OptionList.ContainsKey(OptionName))
            {
                // found an option page
                OptionDefaults optPage = (OptionDefaults)OptionList[OptionName];
            }

        }


        public class OptionDefaults
        {
            protected Control[] ControlArr;
            protected Panel _cParent;
            protected string _Name="NEW";

            public string Name
            {
                get { return _Name; }
            }
            public Panel cParent
            {
                get { return _cParent; }
                set { _cParent = value; }
            }

            public void DisplayFormControls()
            {
                _cParent.Controls.AddRange(ControlArr);
            }

            /// <summary>
            /// Override this class to build it
            /// </summary>
            protected void BuildFormControls()
            {
            }
        }
        
        /// <summary>
        /// General options
        /// </summary>
        public class OptionGeneral : OptionDefaults
        {
            public OptionGeneral(Panel parentcontrol) 
            {
                _Name = "General";
                _cParent = parentcontrol;
                BuildFormControls();
            }
            /*
            public override void BuildFormControls()
            {
                Button newButton = new Button();
                newButton.Name = "btnNewButton";
                newButton.Text = "btnNewButton";
                newButton.Click += new EventHandler(newButton_Click);
                
                ControlArr = new Control[1] { newButton };
            }
            */
            private void newButton_Click(object sender, EventArgs e)
            {
                _cParent.Controls["btnNewButton"].Text = "clicked";
            }
        }


    }
}
